﻿using System;
using System.ComponentModel;
using System.IO;
using System.Runtime.Serialization;

namespace HalconDotNet
{
	/// <summary>Represents an instance of a Deep Neural Network.</summary>
	// Token: 0x02000032 RID: 50
	[Serializable]
	public class HDlClassifier : HHandle, ISerializable, ICloneable
	{
		// Token: 0x06000493 RID: 1171 RVA: 0x0000883B File Offset: 0x00006A3B
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HDlClassifier() : base(HHandleBase.UNDEF)
		{
		}

		// Token: 0x06000494 RID: 1172 RVA: 0x0001B990 File Offset: 0x00019B90
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HDlClassifier(IntPtr handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x06000495 RID: 1173 RVA: 0x0001B99F File Offset: 0x00019B9F
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HDlClassifier(HHandle handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x06000496 RID: 1174 RVA: 0x0001B9AE File Offset: 0x00019BAE
		private void AssertSemType()
		{
			base.AssertSemType("dl_classifier");
		}

		// Token: 0x06000497 RID: 1175 RVA: 0x0001B9BB File Offset: 0x00019BBB
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HDlClassifier obj)
		{
			obj = new HDlClassifier(HHandleBase.UNDEF);
			return obj.Load(proc, parIndex, err);
		}

		// Token: 0x06000498 RID: 1176 RVA: 0x0001B9D4 File Offset: 0x00019BD4
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HDlClassifier[] obj)
		{
			HTuple htuple;
			err = HTuple.LoadNew(proc, parIndex, err, out htuple);
			obj = new HDlClassifier[htuple.Length];
			for (int i = 0; i < htuple.Length; i++)
			{
				obj[i] = new HDlClassifier(HalconAPI.IsLegacyHandleMode() ? htuple[i].IP : htuple[i].H);
			}
			htuple.Dispose();
			return err;
		}

		/// <summary>
		///   Read a deep-learning-based classifier from a file.
		///   Modified instance represents: Handle of the deep learning classifier.
		/// </summary>
		/// <param name="fileName">File name. Default: "pretrained_dl_classifier_compact.hdl"</param>
		// Token: 0x06000499 RID: 1177 RVA: 0x0001BA44 File Offset: 0x00019C44
		public HDlClassifier(string fileName)
		{
			IntPtr proc = HalconAPI.PreCall(2122);
			HalconAPI.StoreS(proc, 0, fileName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		// Token: 0x0600049A RID: 1178 RVA: 0x0001BA90 File Offset: 0x00019C90
		void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
		{
			HSerializedItem hserializedItem = this.SerializeDlClassifier();
			byte[] value = hserializedItem;
			hserializedItem.Dispose();
			info.AddValue("data", value, typeof(byte[]));
		}

		// Token: 0x0600049B RID: 1179 RVA: 0x0001BAC8 File Offset: 0x00019CC8
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HDlClassifier(SerializationInfo info, StreamingContext context)
		{
			HSerializedItem hserializedItem = new HSerializedItem((byte[])info.GetValue("data", typeof(byte[])));
			this.DeserializeDlClassifier(hserializedItem);
			hserializedItem.Dispose();
		}

		/// <summary>Serialize object to binary stream in HALCON format</summary>
		// Token: 0x0600049C RID: 1180 RVA: 0x0001BB08 File Offset: 0x00019D08
		public new void Serialize(Stream stream)
		{
			HSerializedItem hserializedItem = this.SerializeDlClassifier();
			hserializedItem.Serialize(stream);
			hserializedItem.Dispose();
		}

		/// <summary>Deserialize object from binary stream in HALCON format</summary>
		// Token: 0x0600049D RID: 1181 RVA: 0x0001BB1C File Offset: 0x00019D1C
		public new static HDlClassifier Deserialize(Stream stream)
		{
			HDlClassifier hdlClassifier = new HDlClassifier();
			HSerializedItem hserializedItem = HSerializedItem.Deserialize(stream);
			hdlClassifier.DeserializeDlClassifier(hserializedItem);
			hserializedItem.Dispose();
			return hdlClassifier;
		}

		// Token: 0x0600049E RID: 1182 RVA: 0x0001BB42 File Offset: 0x00019D42
		object ICloneable.Clone()
		{
			return this.Clone();
		}

		// Token: 0x0600049F RID: 1183 RVA: 0x0001BB4C File Offset: 0x00019D4C
		public new HDlClassifier Clone()
		{
			HSerializedItem hserializedItem = this.SerializeDlClassifier();
			HDlClassifier hdlClassifier = new HDlClassifier();
			hdlClassifier.DeserializeDlClassifier(hserializedItem);
			hserializedItem.Dispose();
			return hdlClassifier;
		}

		/// <summary>
		///   Infer the class affiliations for a set of images using a  deep-learning-based classifier.
		///   Instance represents: Handle of the deep-learning-based classifier.
		/// </summary>
		/// <param name="images">Tuple of input images.</param>
		/// <returns>Handle of the deep learning classification  results.</returns>
		// Token: 0x060004A0 RID: 1184 RVA: 0x0001BB74 File Offset: 0x00019D74
		public HDlClassifierResult ApplyDlClassifier(HImage images)
		{
			IntPtr proc = HalconAPI.PreCall(2102);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, images);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HDlClassifierResult result;
			num = HDlClassifierResult.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			GC.KeepAlive(images);
			return result;
		}

		/// <summary>Clear a deep-learning-based classifier.</summary>
		/// <param name="DLClassifierHandle">Handle of the deep-learning-based classifier.</param>
		// Token: 0x060004A1 RID: 1185 RVA: 0x0001BBCC File Offset: 0x00019DCC
		public static void ClearDlClassifier(HDlClassifier[] DLClassifierHandle)
		{
			HTuple htuple = HHandleBase.ConcatArray(DLClassifierHandle);
			IntPtr proc = HalconAPI.PreCall(2103);
			HalconAPI.Store(proc, 0, htuple);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(htuple);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(DLClassifierHandle);
		}

		/// <summary>
		///   Clear a deep-learning-based classifier.
		///   Instance represents: Handle of the deep-learning-based classifier.
		/// </summary>
		// Token: 0x060004A2 RID: 1186 RVA: 0x0001BC10 File Offset: 0x00019E10
		public void ClearDlClassifier()
		{
			IntPtr proc = HalconAPI.PreCall(2103);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Deserialize a deep-learning-based classifier.
		///   Modified instance represents: Handle of the deep-learning-based classifier.
		/// </summary>
		/// <param name="serializedItemHandle">Handle of the serialized item.</param>
		// Token: 0x060004A3 RID: 1187 RVA: 0x0001BC44 File Offset: 0x00019E44
		public void DeserializeDlClassifier(HSerializedItem serializedItemHandle)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(2109);
			HalconAPI.Store(proc, 0, serializedItemHandle);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			GC.KeepAlive(serializedItemHandle);
		}

		/// <summary>
		///   Return the parameters of a deep-learning-based classifier.
		///   Instance represents: Handle of the deep-learning-based classifier.
		/// </summary>
		/// <param name="genParamName">Name of the generic parameter. Default: "gpu"</param>
		/// <returns>Value of the generic parameter.</returns>
		// Token: 0x060004A4 RID: 1188 RVA: 0x0001BC98 File Offset: 0x00019E98
		public HTuple GetDlClassifierParam(HTuple genParamName)
		{
			IntPtr proc = HalconAPI.PreCall(2114);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, genParamName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(genParamName);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Return the parameters of a deep-learning-based classifier.
		///   Instance represents: Handle of the deep-learning-based classifier.
		/// </summary>
		/// <param name="genParamName">Name of the generic parameter. Default: "gpu"</param>
		/// <returns>Value of the generic parameter.</returns>
		// Token: 0x060004A5 RID: 1189 RVA: 0x0001BCF0 File Offset: 0x00019EF0
		public HTuple GetDlClassifierParam(string genParamName)
		{
			IntPtr proc = HalconAPI.PreCall(2114);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, genParamName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Read a deep-learning-based classifier from a file.
		///   Modified instance represents: Handle of the deep learning classifier.
		/// </summary>
		/// <param name="fileName">File name. Default: "pretrained_dl_classifier_compact.hdl"</param>
		// Token: 0x060004A6 RID: 1190 RVA: 0x0001BD40 File Offset: 0x00019F40
		public void ReadDlClassifier(string fileName)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(2122);
			HalconAPI.StoreS(proc, 0, fileName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Serialize a deep-learning-based classifier.
		///   Instance represents: Handle of the deep-learning-based classifier.
		/// </summary>
		/// <returns>Handle of the serialized item.</returns>
		// Token: 0x060004A7 RID: 1191 RVA: 0x0001BD8C File Offset: 0x00019F8C
		public HSerializedItem SerializeDlClassifier()
		{
			IntPtr proc = HalconAPI.PreCall(2126);
			base.Store(proc, 0);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HSerializedItem result;
			num = HSerializedItem.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Set the parameters of a deep-learning-based classifier.
		///   Instance represents: Handle of the deep-learning-based classifier.
		/// </summary>
		/// <param name="genParamName">Name of the generic parameter. Default: "classes"</param>
		/// <param name="genParamValue">Value of the generic parameter. Default: ["class_1","class_2","class_3"]</param>
		// Token: 0x060004A8 RID: 1192 RVA: 0x0001BDD4 File Offset: 0x00019FD4
		public void SetDlClassifierParam(HTuple genParamName, HTuple genParamValue)
		{
			IntPtr proc = HalconAPI.PreCall(2128);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, genParamName);
			HalconAPI.Store(proc, 2, genParamValue);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(genParamName);
			HalconAPI.UnpinTuple(genParamValue);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Set the parameters of a deep-learning-based classifier.
		///   Instance represents: Handle of the deep-learning-based classifier.
		/// </summary>
		/// <param name="genParamName">Name of the generic parameter. Default: "classes"</param>
		/// <param name="genParamValue">Value of the generic parameter. Default: ["class_1","class_2","class_3"]</param>
		// Token: 0x060004A9 RID: 1193 RVA: 0x0001BE24 File Offset: 0x0001A024
		public void SetDlClassifierParam(string genParamName, string genParamValue)
		{
			IntPtr proc = HalconAPI.PreCall(2128);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, genParamName);
			HalconAPI.StoreS(proc, 2, genParamValue);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Write a deep-learning-based classifier in a file.
		///   Instance represents: Handle of the deep-learning-based classifier.
		/// </summary>
		/// <param name="fileName">File name.</param>
		// Token: 0x060004AA RID: 1194 RVA: 0x0001BE68 File Offset: 0x0001A068
		public void WriteDlClassifier(string fileName)
		{
			IntPtr proc = HalconAPI.PreCall(2132);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, fileName);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}
	}
}
